package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/iot")
@Api(tags = "管理端 - 物联网iot相关接口")
public class DeviceController extends BaseController {
    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    @ApiOperation(value = "从物联网平台同步产品列表")
    public ResponseResult<Void> syncProductList() {
        deviceService.syncProductList();
        return success();
    }

    @GetMapping("/allProduct")
    @ApiOperation(value = "查询所有产品列表")
    public ResponseResult<List<ProductVo>> allProduct() {
        return success(deviceService.allProduct());
    }

    @PostMapping("/RegisterDevice")
    @ApiOperation(value = "注册设备")
    public ResponseResult<Void> registerDevice(@RequestBody DeviceDto deviceDto) {
        return deviceService.registerDevice(deviceDto);
    }

    @GetMapping("/pageQueryDevice")
    @ApiOperation(value = "分页查询设备列表")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto params) {
        return success(deviceService.page(params));
    }

    @PostMapping("/QueryDeviceDetail")
    @ApiOperation(value = "查询设备详情")
    public ResponseResult<DeviceVo> QueryDeviceDetail(@RequestBody DeviceDto deviceDto) {
        return success(deviceService.queryDeviceDetail(deviceDto));
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询设备运行状态")
    public ResponseResult<List<DeviceVo>> QueryDevicePropertyStatus(@RequestBody DeviceDto deviceDto) {
        return success(deviceService.queryDevicePropertyStatus(deviceDto));
    }

    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查询物模型")
    public ResponseResult<List<DeviceVo>> QueryThingModelPublished(@RequestBody DeviceDto deviceDto) {
        return success(deviceService.QueryThingModelPublished(deviceDto));
    }

    @PostMapping("/UpdateDevice")
    @ApiOperation(value = "修改设备")
    public ResponseResult<Void> UpdateDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.updateDevice(deviceDto);
        return success();
    }

    @DeleteMapping("/DeleteDevice")
    @ApiOperation(value = "删除设备")
    public ResponseResult<Void> DeleteDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.deleteDevice(deviceDto);
        return success();
    }


}